package com.ruitu.mall_98_2.mvp.presenter;

import com.beanu.arad.utils.ToastUtils;
import com.ruitu.mall_98_2.mvp.contract.AddressListContract;
import com.ruitu.router_module.bean.api.BaseResult;
import com.ruitu.router_module.bean.api.SubscriberImpl;
import com.ruitu.router_module.bean.mine.Address;

import java.util.List;

public class AddressListPresenter extends AddressListContract.Presenter {
    @Override
    public void getMineAddress(String accountId) {
        mModel.getMineAddress(accountId)
                .subscribe(new SubscriberImpl<BaseResult<List<Address>>>() {
                    @Override
                    public void onError(Throwable e) {
                        mView.setFail();
                        mView.hideProgress();
                        ToastUtils.showShort("获取收货地址失败");
                    }

                    @Override
                    public void onNext(BaseResult<List<Address>> listBaseResult) {
                        mView.hideProgress();
                        if (listBaseResult.isSuccess()){
                            mView.setData(listBaseResult.getData());
                        }else {
                            ToastUtils.showShort(listBaseResult.getMsg());
                        }
                    }
                });
    }
}
